const axios = require('axios');

export const Url = process.env.REACT_APP_URL
const Api = {}

// 配置请求拦截器
axios.interceptors.request.use(function (config) {
    // console.log('请求拦截器',config.url,window.localStorage.getItem('openId'))
    config.headers.openId = window.localStorage.getItem('openId');
    return config;
}, function (err) {
    console.log('请求拦截器错误', err)
})

// 获取个人信息
Api.getPersonalInfo = () => {
    return axios({
        method: 'get',
        url: Url + 'getPersonalInfo/',
        withCredentials: true//允许共享session
    })
}
// 修改个人信息
Api.alertPersonalInfo = (data) => {
    return axios({
        method: 'post',
        url: Url + 'alertPersonalInfo/',
        data,
        withCredentials: true
    })
}
// 新增文章
Api.addArticle = (data) => {
    return axios({
        method: 'post',
        url: Url + 'addArticle/',
        data,
        withCredentials: true
    })
}
// 获取文章
Api.alertArticle = (data) => {
    return axios({
        method: 'post',
        url: Url + 'alertArticle/',
        data,
        withCredentials: true
    })
}
// 获取文章列表
Api.getArticleList = () => {
    return axios({
        method: 'get',
        url: Url + 'getArticleList/',
        withCredentials: true
    })
}
// 删除文章
Api.deleteArticle = (id) => {
    return axios({
        method: 'get',
        url: Url + 'deleteArticle/' + id,
        withCredentials: true
    })
}
// 获取文章
Api.getArticle = (id) => {
    return axios({
        method: 'get',
        url: Url + 'getArticle/' + id,
        withCredentials: true
    })
}
// 获取技术
Api.getSkillType = () => {
    return axios({
        method: 'get',
        url: Url + 'getSkillType/',
        withCredentials: true
    })
}
// 获取留言
Api.guestbook = () => {
    return axios({
        method: 'get',
        url: Url + 'guestbook/',
        withCredentials: true
    })
}
// 删除留言
Api.deleteGuestbook = (id) => {
    return axios({
        method: 'get',
        url: Url + 'deleteGuestbook/' + id,
        withCredentials: true
    })
}
// 获取生活
Api.liveList = () => {
    return axios({
        method: 'get',
        url: Url + 'liveList/',
        withCredentials: true
    })
}
// 删除生活
Api.deleteLive = (id) => {
    return axios({
        method: 'get',
        url: Url + 'deleteLive/' + id,
        withCredentials: true
    })
}
// 新增生活
Api.addLive = (data) => {
    return axios({
        method: 'post',
        url: Url + 'addLive/',
        data,
        withCredentials: true
    })
}
// 登陆
Api.login = (data) => {
    return axios({
        method: 'post',
        url: Url + 'login/',
        data,
        withCredentials: true
    })
}
// 登陆
Api.login = (data) => {
    return axios({
        method: 'post',
        url: Url + 'login/',
        data,
        withCredentials: true
    })
}
// 判断是否登陆
Api.isLogin = () => {
    return axios({
        method: 'get',
        url: Url + 'index/',
        withCredentials: true
    })
}
// 登出
Api.loginout = () => {
    return axios({
        method: 'get',
        url: Url + 'loginout/',
        withCredentials: true
    })
}
// 修改密码
Api.alertPassword = (data) => {
    return axios({
        method: 'post',
        url: Url + 'alertPassword/',
        data,
        withCredentials: true
    })
}

// 上传文章背景
// Api.uploadBgi=(data)=>{
//     return axios({
//         method:'post',
//         url: Url + 'uploadBgi/',
//         data
//     })
// }


export default Api